function common() {}

/*  性别编码转中文
*/
common.prototype.sexToText = (sex) => {
    switch (sex) {
        case "0":
            return "女"
        case "1":
            return "男"
        case "2":
            return "未知"
        default:
            return "未知"
    }
}

/*  出生日期转年龄
*/
common.prototype.birthToAge = (birth) => {
    if (!birth) return "暂无数据";
    var birthYear = Number(new common().dateFormat(birth).y)
    var thisYear = new Date().getFullYear()
    // console.log(birthYear, thisYear, thisYear - birthYear);
    return thisYear - birthYear
}

/*  格式化时间
*/
common.prototype.dateFormat = (dateTime) => {
    if (typeof (dateTime) != 'string') dateTime = String(dateTime)
    var dateParse = Date.parse(new Date(dateTime)); // 转成时间戳
    var time = new Date(dateParse); // 再转成标准时间
    var y = String(time.getFullYear());
    var m = String(time.getMonth() + 1);
    var d = String(time.getDate());
    var h = String(time.getHours());
    var u = String(time.getMinutes());
    var s = String(time.getSeconds());
    return { y, m, d, h, u, s }
}
